﻿package hu.vpszd.entities.transaction

import hu.vpszd.entities.BaseEntity
import hu.vpszd.entities.User
import hu.vpszd.entities.customer.Address
import hu.vpszd.entities.customer.CheckingAccount;

import javax.persistence.CascadeType
import javax.persistence.Embedded
import javax.persistence.Entity
import javax.persistence.ManyToOne
import javax.persistence.OneToMany
import javax.persistence.Table
import javax.validation.constraints.Max;
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern

import org.hibernate.annotations.LazyCollection
import org.hibernate.annotations.LazyCollectionOption
//import org.hibernate.annotations.Fetch;

@Entity
@Table(name = "LoanApplication")
class LoanApplication extends BaseEntity{

	@NotNull
	Integer status = 0
	//Ezek tartoznak a MinimumConditionCheckerServiceImpl.groovy
	Boolean isIncomeAmountEnough = false
	Boolean isLengthOfEmployementEnough = false
	Boolean isAgeEnough = false
	//Ha ez false akkor nem lehet kalkulálni, ajánlatot nyomtatni befejezni a feladatot
	Boolean isMinimumConditionApproved = false

	Boolean isCalculated = false

	//Ha jót kalkulált akkor true az ajánlat/előszűrés
	Boolean isOfferApproved = false
	Boolean isOfferPrinted = false

	//Ha jót kalkulált akkor true az igénylés
	Boolean isApplicationApproved = false
	Boolean isContractPrinted = false

	Boolean isContractSigned = false
	
	Boolean isVerificationApproved = false 
	
	Boolean isDisburesementSuccessful = false

	Integer loanType

	//	@NotNull
	String loanTypeName

	@NotNull
	@Min(value = 200000L)
	@Max(value = 3000000L)
	Integer loanAmountByCustomer

	@NotNull
	@Min(value = 1L)
	@Max(value = 3000000L)
	Integer loanAmountByBank = 0

	@NotNull
	@Min(value = 24L)
	@Max(value = 84L)
	Integer durationByCustomer

	@NotNull
	@Min(value = 1L)
	@Max(value = 120L)
	Integer durationByBank = 0

	//	Törlesztőrészlet
	@NotNull
	Integer installment

	
	String loanCoverInsurrance
	//	@NotNull
	String bankAccountNumber
	@ManyToOne
	CheckingAccount checkingAccount

	//kamat
	//	@NotNull
	Double interest

//	@NotNull
	@ManyToOne
	User user
	String action


	//	Mindháromnak meg kell lennie
	//	@NotNull
	Boolean hasAddressCard
	//	@NotNull
	Boolean hasIDCard
	//	@NotNull
	Boolean hasTaxCard
	Date birthday
	//	Magyar vs külföldi
	//	@NotNull
	String citizenship
	//	@NotNull
	String education
	//	@NotNull
	String maritalStatus
	//	@NotNull
	@Embedded
	Address address = new Address()
	//	@NotNull
	String residency
	@Pattern(regexp = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})\$")
	String emailAddress
	//	@NotNull
	String mobilePhone
	//	@NotNull
	String wiredPhone
	String otherPhone

	//	@NotNull
	@OneToMany(cascade = CascadeType.ALL)
	@LazyCollection(LazyCollectionOption.FALSE)
	List<Income> incomes = []


	@OneToMany(cascade = CascadeType.ALL)
	@LazyCollection(LazyCollectionOption.FALSE)
	List<ExistingLoanDebt> existingLoanDebts = []

	@Embedded
	Verification verification = new Verification()}